﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using NetDiskPRJ.DBUtility;

namespace NetDiskPRJ.DAL
{
	/// <summary>
	/// 数据访问类:PrvUserGroup
	/// </summary>
	public partial class PrvUserGroup
	{
		public PrvUserGroup()
		{}
        /// <summary>
        /// 根据用户ID获取用户组ID列表
        /// <creator>wangl</creator>
        /// <date>2013-02-17</date>
        /// </summary>
        /// <param name="logID"></param>
        /// <returns></returns>
        public DataSet GetGrpListByLogid(string logID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FLogID,FGroupNo from t_PrvUserGroup ");
            strSql.Append(" WHERE FLogID=@FLogID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,30)};
            parameters[0].Value = logID;

            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获得数据列表
        ///<creator>zhongyl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FLogID,FGroupNo ");
            strSql.Append(" FROM t_PrvUserGroup ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }




        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-02-17</date>
        /// </summary>
        public NetDiskPRJ.Model.PrvUserGroup DataRowToModel(DataRow row)
        {
            NetDiskPRJ.Model.PrvUserGroup model = new NetDiskPRJ.Model.PrvUserGroup();
            if (row != null)
            {
                if (row["FLogID"] != null)
                {
                    model.FLogID = row["FLogID"].ToString();
                }
                if (row["FGroupNo"] != null)
                {
                    model.FGroupNo = row["FGroupNo"].ToString();
                }
            }
            return model;
        }
        /// <summary>
        /// 删除用户组并删除该用户组下的用户权限
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        public bool DeleteGrpById(string groupNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_PrvUserGroup ");
            strSql.Append(" where FGroupNo=@FGroupNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FGroupNo", SqlDbType.NVarChar,10)};
            parameters[0].Value = groupNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 增加一条数据
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        public bool Add(Model.PrvUserGroup model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_PrvUserGroup(");
            strSql.Append("FLogID,FGroupNo)");
            strSql.Append(" values (");
            strSql.Append("@FLogID,@FGroupNo)");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,30),
					new SqlParameter("@FGroupNo", SqlDbType.NVarChar,10)};
            parameters[0].Value = model.FLogID;
            parameters[1].Value = model.FGroupNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// <creator>wangl</creator>
        /// <date>2013-02-18</date>
        /// </summary>
        public bool Delete(string logID, string groupNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_PrvUserGroup ");
            strSql.Append(" where FLogID=@FLogID and FGroupNo=@FGroupNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FLogID", SqlDbType.NVarChar,30),
					new SqlParameter("@FGroupNo", SqlDbType.NVarChar,10)			};
            parameters[0].Value = logID;
            parameters[1].Value = groupNo;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
	}
}

